import { route } from '../decorators';
import { Response } from '../common';
import { Util } from "../utils/";
import { CnsService } from "../cns/cnsService";
import { Cns } from "../cns/cns";

export class NotifyController {
    private util: Util
    constructor() { 
        this.util = Util.Current;
    }
    /**
     * 订单通知
     * @param  {} type 类型
     * @param  {} msg 提示信息
     */
    @route({ method: 'post', path: '/notify' })
    async notify(ctx, next) {
        let body = ctx.request.body;
        try {
            body = this.util.text2Obj(body);
            let storeId = body.storeId;
            let msg = body.msg;
            await Cns.Current.Server.Notify(storeId, msg);
            ctx.response.body = Response.ok("通知成功", null);
        } catch (error) {
            console.log("error===>",error);
            ctx.response.body = Response.JSONException(error);
        } finally {
            await next();
        }
    }
}